import { _decorator, Component, director, Node, SpringJoint2D, Sprite, UITransform } from 'cc';
import { GameConfig } from '../../GameConfig';
import BaseComp from '../../common/BaseComp';
import { eliminateGameManager } from './EliminateGameManager';
import NDB from '../../common/NDBTS';
import { GameOverReason } from './EliminateGame';
const { ccclass, property } = _decorator;

@ccclass('EliminateMatch3Pause')
export class EliminateMatch3Pause extends BaseComp {

    private btns: UITransform = null;

    private next: Sprite = null;
    private continue: Sprite = null;
    private restart: Sprite = null;
    private exit: Sprite = null;

    __preload(): void {
        this.openFilter = true;
        super.__preload();
    }

    start() {

    }

    onEnable(): void {
        const overReason = eliminateGameManager.game.overReason;
        if (overReason == GameOverReason.COUNTDOWN_OVER || overReason == GameOverReason.NOT_COMPLETE_LEVEL) {
            this.next.node.active = false;
            this.continue.node.active = false;
        } else if (overReason == GameOverReason.NORMAL_OVER) {
            this.next.node.active = true;
            this.continue.node.active = false;
        }
    }

    update(deltaTime: number) {

    }

    btnEvents(event: any, data: string) {
        switch (data) {
            case "continue":
                break;
            case "restart":
                director.loadScene(`${GameConfig.gameName}_GameScene`, (err) => {
                    if (err) {
                        return;
                    }
                });
                break;
            case "exit":
                if (eliminateGameManager.game.isDebug) {
                    NDB.closeWebView();
                } else {
                    eliminateGameManager.game.leaveGame().then(() => {
                        NDB.closeWebView();
                    })
                }
                // 退出游戏
                break;
            case "close":
                break;
            case "next":
                eliminateGameManager.curPlayLevel++;
                director.loadScene(`${GameConfig.gameName}_GameScene`, (err) => {
                    if (err) {
                        return;
                    }
                });
                break;
        }
        this.node.active = false;
    }
}

